package me.hl.concurrent;

import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by pulangke on 2017/3/30.
 */
public class ListTest {


    @Test
    public void test() throws Exception {
        ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        Thread thread = new Thread(() -> {
            try {
                concurrentHashMap.put("aaa", simpleDateFormat.format(new Date()));
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        Thread thread1 = new Thread(() -> {

            Set<Map.Entry<String, String>> set = concurrentHashMap.entrySet();
            for (Map.Entry<String, String> entry : set) {
                try {
                    System.out.println(entry.getValue());
                    Thread.sleep(1500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });


        thread.start();
        Thread.sleep(1100);
        thread1.start();

        Thread.sleep(100000);

    }
}
